//package com.fromfuture.xuhuidoc.android.activity;
//
//import android.app.Activity;
//import android.content.Context;
//import android.os.Bundle;
//import android.os.Handler;
//import android.os.Looper;
//import android.os.Message;
//import android.support.annotation.Nullable;
//import android.util.Log;
//import android.widget.Toast;
//
//import com.dooble.phonertc.PhoneRTCPlugin;
//import com.dooble.phonertc.Session;
//import com.dooble.phonertc.SessionConfig;
//import com.fromfuture.xuhuidoc.android.utils.DialogUtil;
//import com.umeng.commonsdk.statistics.proto.a;
//
//import org.apache.cordova.CallbackContext;
//import org.apache.cordova.CordovaActivity;
//import org.apache.cordova.CordovaWebView;
//import org.java_websocket.client.WebSocketClient;
//import org.java_websocket.drafts.Draft;
//import org.java_websocket.handshake.ServerHandshake;
//import org.json.JSONException;
//import org.json.JSONObject;
//
//import java.io.BufferedReader;
//import java.io.FileInputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.InputStreamReader;
//import java.io.OutputStream;
//import java.net.InetSocketAddress;
//import java.net.Socket;
//import java.net.SocketTimeoutException;
//import java.net.URI;
//import java.net.URISyntaxException;
//import java.net.UnknownHostException;
//import java.nio.ByteBuffer;
//import java.util.concurrent.ExecutorService;
//import java.util.concurrent.Executors;
//import java.util.concurrent.TimeUnit;
//
//import app.auto.runner.ActivityBaseCompact;
//import app.auto.runner.base.utility.ToastUtil;
//
///**
// * Created by hp on 2018/3/2.
// */
//
//public class PersonsChatActivity extends CordovaActivity {
//
//    @Override
//    public void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
////        connectWebSocketClient(this);
//        JSONObject jsonObject = new JSONObject();
//        try {
//            jsonObject.put("isInitiator", true);
//            jsonObject.put("host", "turn:u1@36.111.43.9:3478");
//            jsonObject.put("username", "ul");
//
//            jsonObject.put("password", "0");
//            JSONObject streams = new JSONObject();
//            streams.put("audio", true);
//            jsonObject.put("streams", true);
//
//
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
//        try {
//
//            Session session = new Session(new PhoneRTCPlugin(),new CallbackContext("callbackid", getCordovaWebView()), SessionConfig.fromJSON(jsonObject),System.currentTimeMillis()+"");
//            session.call();
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
//
//
//    }
//
//    protected void connectWebSocketClient(final Context ctx) {
//        WebSocketClient client = null;
//        try {
//            client = new WebSocketClient(new URI("wss://gz.fromfuture.cn:9010")) {
//                @Override
//                public void onOpen(ServerHandshake handshakedata) {
//                        String room = "{\"eventName\": \"__join\", \"data\": {\"room\": 1}}";
//                        send(room);
//                }
////{"eventName":"_peers","data":{"connections":[],"you":"5d1bf565-d1ad-4ae9-a8ea-386174ec3156"}}
//
//                @Override
//                public void onMessage(final String message) {
//                    runOnUiThread(new Runnable() {
//                        @Override
//                        public void run() {
//
//                            Toast.makeText(ctx, message, Toast.LENGTH_SHORT).show();
//                        }
//                    });
//                }
//
//                @Override
//                public void onClose(int code, String reason, boolean remote) {
//
//                }
//
//                @Override
//                public void onError(Exception ex) {
//
//                }
//            };
//        } catch (URISyntaxException e) {
//            e.printStackTrace();
//        }
//        client.connect();
//
//    }
//
//    public static class EmptyClient extends WebSocketClient {
//
//        public EmptyClient(URI serverUri, Draft draft) {
//            super(serverUri, draft);
//        }
//
//        public EmptyClient(URI serverURI) {
//            super(serverURI);
//        }
//
//        @Override
//        public void onOpen(ServerHandshake handshakedata) {
//            send("Hello, it is me. Mario :)");
//            System.out.println("new connection opened");
//        }
//
//        @Override
//        public void onClose(int code, String reason, boolean remote) {
//            System.out.println("closed with exit code " + code + " additional info: " + reason);
//        }
//
//        @Override
//        public void onMessage(String message) {
//            System.out.println("received message: " + message);
//        }
//
//        @Override
//        public void onMessage(ByteBuffer message) {
//            System.out.println("received ByteBuffer");
//        }
//
//        @Override
//        public void onError(Exception ex) {
//            System.err.println("an error occurred:" + ex);
//        }
//
//        public static void main(String[] args) throws URISyntaxException {
//            WebSocketClient client = new EmptyClient(new URI("ws://localhost:8887"));
//            client.connect();
//        }
//    }
//}